<?php
require_once '../sub/init.php';
header("Cache-control: private");
require_once 'chkUadm.php';
require_once ZEAI.'sub/zeai_up_func.php';
if(!in_array('manghe',$QXARR))exit(noauth());
$fid=intval($fid);
$row = $db->ROW(__TBL_MANGHE__,"id","id=".$fid,"num");
if (!$row){
	exit('<br><br>项目不存在或已被删除');
}
if($submitok=='add_update' || $submitok=='mod_update'){
	$uid=intval($uid);
	if(ifint($uid)){
		$row = $db->ROW(__TBL_USER__,"openid","id=".$uid,"name");
		if (!$row)alert_adm("主表找不到此用户","-1");
		$openid=$row['openid'];
	}
	$uid      = intval($uid);
	$sex      = intval($sex);
	$outnum   = intval($outnum);
	$weixin = trimhtml(dataIO($weixin,'in'),50);
	$aboutus = trimhtml(dataIO($aboutus,'in'),500);
	if(!ifint($sex) || empty($weixin))alert_adm("【性别】和【微信】必填".$weixin,"-1");
}
if($submitok=='add_update'){
	if(ifint($uid)){
		$row = $db->ROW(__TBL_MANGHE_U__,"id","uid<>'' AND uid=".$uid);
		if ($row)alert_adm("此用户已经存在记录，建议修改","-1");
	}
	$row = $db->ROW(__TBL_MANGHE_U__,"id","weixin<>'' AND weixin='$weixin' AND fid=".$fid);
	if ($row)alert_adm("此微信【".$weixin."】已存在，请更换其它","-1");
	$db->query("INSERT INTO ".__TBL_MANGHE_U__."  (sex,weixin,aboutus,fid,uid,openid,addtime,flag,flag2,outnum) VALUES ('$sex','$weixin','$aboutus','$fid','$uid','$openid',".ADDTIME.",1,1,$outnum)");	
	AddLog('手动新增盲盒用户->【'.$weixin.'（uid:'.$uid.'）】');
	alert_adm("新增成功","manghe_u.php?fid=".$fid);
}elseif($submitok=='mod_update'){
	if (!ifint($id))alert_adm("id参数错误","-1");
	if($oldweixin != $weixin){
		$row = $db->ROW(__TBL_MANGHE_U__,"id","weixin<>'' AND weixin='$weixin' AND fid=".$fid);
		if ($row)alert_adm("此微信【".$weixin."】已存在，请更换其它","-1");
		$SQL = ",weixin='$weixin'";
	}
	$row = $db->ROW(__TBL_MANGHE_U__,"path_b","id=".$id,"name");
	$path_b=$row['path_b'];
	if(!empty($path_b))UP_modFn('adm','s',$path_b);
	/*	
	$rt=$db->query("SELECT path_b FROM ".__TBL_MANGHE_U__." WHERE path_b<>'' ORDER BY id DESC");
	$total = $db->num_rows($rt);
	if ($total >0) {
		for($i=1;$i<=$total;$i++) {
			$rows = $db->fetch_array($rt,'name');
			if(!$rows) break;
			$path_b=$rows['path_b'];
			if(!empty($path_b))UP_modFn('adm','s',$path_b);
		}
	}
	*/
	if(!empty($openid))$SQL = ",openid='$$openid'";
	$db->query("UPDATE ".__TBL_MANGHE_U__." SET uid=$uid,outnum=$outnum,sex=$sex,aboutus='$aboutus'".$SQL." WHERE id=".$id);
	AddLog('修改盲盒用户资料->【'.$weixin.'（uid:'.$uid.'）】');
	alert_adm("修改成功","manghe_u.php?fid=".$fid);
}elseif($submitok=='mod'){
	if (!ifint($id))alert_adm("id参数错误","-1");
	$rt = $db->query("SELECT * FROM ".__TBL_MANGHE_U__." WHERE id=".$id);
	if($db->num_rows($rt)){
		$row   = $db->fetch_array($rt,'name');
        $uid      = $row['uid'];
        $sex      = $row['sex'];
        $outnum   = $row['outnum'];
		$weixin   = trimhtml(dataIO($row['weixin'],'out'));
		$aboutus  = trimhtml(dataIO($row['aboutus'],'out'));
	}else{
		alert_adm("该记录不存在！","-1");
	}	
}elseif($submitok=='ajax_del'){
	$tmeplist = $list;
	if(empty($tmeplist))json_exit(array('flag'=>0,'msg'=>'请选择您要删除的信息'));
	if(!is_array($tmeplist))exit(JSON_ERROR);
	if(count($tmeplist)>=1){
		foreach($tmeplist as $value){$id=intval($value);
			if (!ifint($id))json_exit(array('flag'=>0,'msg'=>'记录不存在'));
			$row = $db->ROW(__TBL_MANGHE_U__,"uid,weixin,path_b","id=".$id);
			if ($row){$uid= $row[0];$weixin= $row[1];$path_b= $row[2];}else{json_exit(array('flag'=>0,'msg'=>'记录不存在'));}
			if(!empty($path_b))@up_send_admindel($path_b);
			$db->query("DELETE FROM ".__TBL_MANGHE_U__." WHERE fid=".$fid." AND id=".$id);
			AddLog('【删除盲盒用户资料】->【uid:'.$uid.'，'.$weixin.'】');
		}
	}
	json_exit(array('flag'=>1,'msg'=>'删除成功'));
}?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="<?php echo HOST;?>/res/www_zeai_cn.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<link href="css/main.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css">
<style>
.listdatabox{padding:10px 0}
.listdatabox li{display:inline-block;padding:1px 5px;border:#ddd 1px solid;margin:3px;border-radius:3px;color:#888}
i.add{display:inline-block;color:#fff;border-radius:50px;width:16px;height:16px;text-align:center;font-size:12px;margin-right:2px}
i.wxlv{color:#31C93C;margin-right:2px}
.timestyle{color:#f00}
</style>
</head>
<body class="body">
<?php 
$SQL = "flag=1 AND fid=".$fid;
$Skey = trimhtml($Skey);
if(ifint($Skey)){
	$SQL .= " AND (uid=$Skey) ";
}elseif(!empty($Skey)){
	$SQL .= " AND ( weixin LIKE '%".$Skey."%' OR aboutus LIKE '%".$Skey."%' )";
}
if($s==1)$SQL .= " AND sex=1 ";
if($s==2)$SQL .= " AND sex=2 ";
if($s==3)$SQL .= " AND uid=0 ";
$rt = $db->query("SELECT * FROM ".__TBL_MANGHE_U__." WHERE ".$SQL." ORDER BY id DESC");
$total = $db->num_rows($rt);
$total0 = $db->COUNT(__TBL_MANGHE_U__,"flag=1 AND fid=".$fid);
$total1 = $db->COUNT(__TBL_MANGHE_U__,"flag=1 AND sex=1 AND fid=".$fid);
$total2 = $db->COUNT(__TBL_MANGHE_U__,"flag=1 AND sex=2 AND fid=".$fid);
$total3 = $db->COUNT(__TBL_MANGHE_U__,"flag=1 AND uid=0 AND fid=".$fid);
$nav0 = (empty($s))?'<b>'.$total0.'</b>':'<b class="border">'.$total0.'</b>';
$nav1 = ($s==1)?'<b>'.$total1.'</b>':'<b class="border">'.$total1.'</b>';
$nav2 = ($s==2)?'<b>'.$total2.'</b>':'<b class="border">'.$total2.'</b>';
$nav3 = ($s==3)?'<b>'.$total3.'</b>':'<b class="border">'.$total3.'</b>';
?>
<div class="navbox">
<a href="manghe_u.php?fid=<?php echo $fid;?>" <?php echo (empty($s))?' class="ed"':'';?>>用户管理<?php echo $nav0;?></a>
<a href="manghe_u.php?fid=<?php echo $fid;?>&s=1" <?php echo ($s==1)?' class="ed"':'';?>>男<?php echo $nav1;?></a>
<a href="manghe_u.php?fid=<?php echo $fid;?>&s=2" <?php echo ($s==2)?' class="ed"':'';?>>女<?php echo $nav2;?></a>
<a href="manghe_u.php?fid=<?php echo $fid;?>&s=3" <?php echo ($s==3)?' class="ed"':'';?>>游客<?php echo $nav3;?></a>
<div class="Rsobox"></div>
<div class="clear"></div></div>
<div class="fixedblank"></div>
<?php if($submitok=='add' || $submitok=='mod'){?>
    <form name="ZEAI_FORM" method="POST" action="<?php echo SELF;?>">
    <table class="table Mtop10 W90_ size2">
    <tr>
      <td class="tdL">用户ID</td>
      <td class="tdR"><input name="uid" id="uid" type="text" class="input size2 W200" value="<?php echo $uid;?>" maxlength="10" placeholder="用户ID，没有留空"  /></td>
    </tr>
    <tr>
      <td class="tdL">性别 <font class="Cf00">*</font></td>
      <td class="tdR">
        <input type="radio" name="sex" id="sex1" class="radioskin" value="1"<?php echo ($sex == 1)?' checked':'';?>><label for="sex1" class="radioskin-label"><i class="i2"></i><b>男</b></label>　
        <input type="radio" name="sex" id="sex2" class="radioskin" value="2"<?php echo ($sex == 2)?' checked':'';?>><label for="sex2" class="radioskin-label"><i class="i2"></i><b>女</b></label>
      </td>
    </tr>
    <tr>
      <td class="tdL">微信 <font class="Cf00">*</font></td>
      <td class="tdR"><input name="weixin" class="input size2 W200" id="weixin" placeholder="输入微信或手机" maxlength="20" value="<?php echo $weixin;?>"autocomplete="off"></td>
    </tr>
    <tr>
      <td class="tdL">介绍</td>
      <td class="tdR"><textarea name="aboutus" rows="3" class="W100_" id="aboutus"><?php echo $aboutus;?></textarea></td>
    </tr>
    <tr>
      <td class="tdL">已取数量</td>
      <td class="tdR"><input name="outnum" class="input size2 W200" id="weixin" maxlength="6" value="<?php echo $outnum;?>"autocomplete="off"></td>
    </tr>
    </table>
    <input type="hidden" name="fid" value="<?php echo $fid;?>" />
    <?php if ($submitok == 'mod'){?>
      <input name="submitok" type="hidden" value="mod_update" />
      <input name="id" type="hidden" value="<?php echo $id;?>" />
      <input name="oldweixin" type="hidden" value="<?php echo $weixin;?>" />
    <?php }else{ ?>
      <input name="submitok" type="hidden" value="add_update" />
    <?php }?>
    <div class="savebtnbox"><button type="submit" class="btn size3">确定并保存</button></div>
</form>
<?php echo '</body></html>'; exit;}
	if ($total <= 0 ) {
		echo "<div class='nodataico Mtop50'><i></i>暂无信息";
		echo "<br><br><a class='aQINGed' href='manghe_u.php?submitok=add&fid=".$fid."'>＋手动增加</a>";
		echo "</div>";
	} else {
		$page_skin = 1;$pagesize=20;require_once ZEAI.'sub/page.php';
	?>
<table class="table0 W95_ Mtop10">
<tr>
<td align="left" class="S14">
  <form name="www.yzlove.com.v6.0..QQ7144100" method="get" action="<?php echo SELF; ?>">
    <input name="Skey" type="text" id="Skey" maxlength="25" class="input size2 W200" placeholder="按UID/微信手机/介绍查询">
    <input type="hidden" name="fid" value="<?php echo $fid;?>" />
    <input type="submit" value="搜索" class="btn size2" />
  </form>   
</td>
<td align="left" class="S14">
</td>
<td align="right" class="S14"><a href="manghe_u.php?submitok=add&fid=<?php echo $fid;?>" class="btn size2" /><i class="ico add">&#xe622;</i>手动增加资料</a></td>
</tr>
</table>
<div class="clear"></div>
<form id="www_zeai_cn_FORM">
    <table class="tablelist" style="width:98%;margin:10px auto 50px auto">
    <tr>
    <th width="20"><input type="checkbox" id="checkboxall1" class="checkskin checkboxall"><label for="checkboxall1" class="checkskin-label"><i class="i1"></i></label></th>
    <th width="60" align="left">　参与用户</th>
    <th width="110" align="left">&nbsp;</th>
    <th align="left">微信/介绍</th>
    <th width="50" align="center">取资料数量</th>
    <th width="70" align="center">时间</th>
    <th width="40" align="center">修改</th>
    <th width="40" align="center">删除</th>
    </tr>
    <?php
    for($i=1;$i<=$pagesize;$i++) {
        $rows = $db->fetch_array($rt,'name');
        if(!$rows) break;
        $id      = $rows['id'];
        $uid     = $rows['uid'];
        $sex     = $rows['sex'];
        $path_b  = $rows['path_b'];
        $addtime = YmdHis($rows['addtime']);
		$weixin = trimhtml(dataIO($rows['weixin'],'outadm'));
		$aboutus = trimhtml(dataIO($rows['aboutus'],'outadm'));
        $outnum  = $rows['outnum'];
		$photo_s = '';$nickname='';$grade=0;
		if(ifint($uid)){
			$row = $db->ROW(__TBL_USER__,"sex,photo_s,grade,nickname","id=".$uid);
			if ($row){
				$photo_s  = $row['photo_s'];
				$sex      = $row['sex'];
				$grade    = $row['grade'];
				$nickname = trimhtml(dataIO($row['nickname'],'out'));
			}
			if(!empty($path_b)){
				$photo_s_url=UP.$path_b;
			}else{
				$photo_s_url = (!empty($photo_s))?UP.$photo_s:RES.'photo_s'.$sex.'.png';
			}
		}else{
			$photo_s_url = (!empty($path_b))?UP.$path_b:RES.'photo_s'.$sex.'.png';
		}
    ?>
	<tr id="tr<?php echo $id;?>">
    <td width="20" height="30" align="left"><input type="checkbox" name="list[]" value="<?php echo $id; ?>" id="id<?php echo $id; ?>" uid="<?php echo $uid; ?>" class="checkskin"><label for="id<?php echo $id; ?>" class="checkskin-label"><i class="i1"></i></label></td>
    <td width="60" height="30" align="center">
    <a href="javascript:;" onClick="parent.piczoom('<?php echo smb($photo_s_url,'b'); ?>');"><img class="photo_s40 yuan" src="<?php echo $photo_s_url; ?>"></a></td>
    <td width="110" height="30" align="left" class="C999">
	<?php
	if(ifint($grade) && ifint($sex)){
		echo uicon($sex.$grade).'<font class="picmiddle C333">'.$uid.'</font></br>　 '.$nickname;
	}else{
		echo '游客';
	}
	?>
    </td>
    <td height="30" align="left" ><?php echo $weixin.'<br>'.$aboutus; ?></td>
    <td width="50" height="30" align="center"><?php echo $outnum; ?></td>
    <td width="70" align="center"><?php echo $addtime;?></td>
    <td width="40" align="center"><a title="修改" fid="<?php echo $fid; ?>" clsid="<?php echo $id; ?>" class="editico"></a></td>
    <td width="40" align="center"><a title="删除" fid="<?php echo $fid; ?>" clsid="<?php echo $id; ?>" class="delico"></a></td>
    </tr>
    <?php } ?>
    <div class="listbottombox">
        <input type="checkbox" id="checkboxall2" class="checkskin checkboxall"><label for="checkboxall2" class="checkskin-label"><i class="i1"></i></label>　
        <button type="button" id="btndellist" value="" class="btn HEI size2 disabled action">删除</button>　　
        <button type="button" id="btnsend" value="" class="btn size2 disabled action" onClick="sendTipFn2(this);" style="display:none"><i class="ico">&#xe676;</i> 发送消息</button>
        <input type="hidden" name="submitok" id="submitok" value="" />
        <?php if ($total > $pagesize)echo '<div class="pagebox FR">'.$pagelist.'</div>'; ?></div>
    </div>
</table>
</form>
<script>
var bg = '<?php echo $_Style['list_bg']; ?>',overbg   = '<?php echo $_Style['list_overbg']; ?>',selectbg = '<?php echo $_Style['list_selectbg']; ?>';
var fid='<?php echo $fid;?>';
zeai.listEach('.delico',function(obj){
	obj.onclick = function(){
		var id = parseInt(obj.getAttribute("clsid")),
		fid = parseInt(obj.getAttribute("fid"));
		zeai.confirm('确定真的要删除么（不可恢复）？',function(){
			zeai.ajax({url:'manghe_u'+zeai.ajxext+'submitok=ajax_del&fid='+fid+'&list[]='+id},function(e){var rs=zeai.jsoneval(e);
				zeai.msg(0);zeai.msg(rs.msg);
				if(rs.flag==1){setTimeout(function(){location.reload(true);},1000);}
			});
		});
	}
});
o('btndellist').onclick = function() {
	allList({
		btnobj:this,
		url:'manghe_u'+zeai.ajxext+'submitok=ajax_del&fid='+fid,
		title:'批量删除',
		msg:'正在删除中...',
		ifjson:true,
		ifconfirm:true
	});	
}
zeai.listEach('.editico',function(obj){
	obj.onclick = function(){
		var id = parseInt(obj.getAttribute("clsid")),
		fid = parseInt(obj.getAttribute("fid"));
		zeai.openurl('manghe_u'+zeai.ajxext+'submitok=mod&fid='+fid+'&id='+id);
	}
});
</script>
<script src="js/zeai_tablelist.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<?php }?>
<br><br><br><br>
</body>
</html>
